<template>
  <div id="app">
    <router-view></router-view>
  </div>
</template>

<script>
export default {
  name: 'App',
    render: h => h(App),
	mounted() {
		window.addEventListener('unload',this.saveState);
	},
	methods:{
		saveState(){
			sessionStorage.setItem('state',JSON.stringify(this.$store.state));
		},
    setLocalStorageAndTime (key, value) {
      window.localStorage.setItem(key, JSON.stringify({ data: value, time: new Date().getTime() }))
    },
    getLocalStorageAndTime (key, exp = 86400000) {
      // 获取数据
      let data = window.localStorage.getItem(key)
      if (!data) return null
      let dataObj = JSON.parse(data)
      // 与过期时间比较
      if (new Date().getTime() - dataObj.time > exp) {
        // 过期删除返回null
        removeLocalStorage(key)
        console.log('信息已过期')
        return null
      } else {
        return dataObj.data
      }
    }


	}
}
</script>

<style>

</style>
